package se.sweco.dataservice;

public class Coord {
	public double lat;
	public double lon;

	public Coord(double lon, double lat) {
		this.lon = lon;
		this.lat = lat;
	}

	public String toString() {
		return "(" + lat + "," + lon + ")";
	}
	
	/* Returns the distance in meters between two coords */
	public double getDistance(Coord o) {
		double r = 6373f * 1000f; // ~Jordens radie (m)
		double lat1 = Math.toRadians(this.lat);
		double lon1 = Math.toRadians(this.lon);
		double lat2 = Math.toRadians(o.lat);
		double lon2 = Math.toRadians(o.lon);
		/* Spherical law of cosines */
		return (r * Math.acos(Math.sin(lat1)*Math.sin(lat2)
				+ Math.cos(lat1)*Math.cos(lat2)*Math.cos(lon2-lon1)));
	}
}
